package net.sinmetal.twitcockpit.twitter;

import net.sinmetal.twitcockpit.model.Robot;
import net.sinmetal.twitcockpit.model.config.TwitterConfig;
import net.sinmetal.twitcockpit.service.ConfigService;
import net.sinmetal.twitcockpit.service.RobotService;
import twitter4j.auth.AccessToken;

/**
 *
 * @author Sinmetal
 *
 */
public class Twitter4tcFactory {

    private ConfigService configService = new ConfigService();

    private RobotService robotService = new RobotService();

    /**
     * TwitCockpit用TwitterAPIオブジェクト生成
     *
     * @return
     */
    public Twitter4tc getInstance() {
        TwitterConfig config = configService.getTwitterConfig();
        return new Twitter4tc(
            config.getConsumerKey(),
            config.getConsumerSecret());
    }

    /**
     * 指定されたRobotのTwitterAPIオブジェクトを生成
     *
     * @param robotTwitterScreenName
     * @return
     */
    public Twitter4tc getInstance(String robotTwitterScreenName) {
        TwitterConfig config = configService.getTwitterConfig();
        Robot robot = robotService.get(robotTwitterScreenName);
        AccessToken accessToken =
            new AccessToken(
                robot.getTwitterToken(),
                robot.getTwitterTokenSecret());
        return new Twitter4tc(
            config.getConsumerKey(),
            config.getConsumerSecret(),
            accessToken);
    }
}
